package com.ztom.offer.v2;

/**
 * 调整数组顺序使奇数位于偶数前面
 * <p>
 * https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/
 *
 * @author ZhangTao
 */
public class Code20Exchange {

    public int[] exchange(int[] nums) {
        if (nums == null || nums.length == 0) {
            return new int[]{};
        }
        int n = nums.length;
        int l = 0;
        int r = 0;
        while (r < n) {
            if ((nums[r] & 1) == 1) {
                int tmp = nums[l];
                nums[l++] = nums[r];
                nums[r++] = tmp;
            } else {
                r++;
            }
        }
        return nums;
    }
}
